import Phaser from 'phaser-ce'
export default class extends Phaser.State {
  constructor ({key}) {
    super()
    this.initState = key
  }
  init () {
    this.stage.backgroundColor = '#0a8cfd'
  }

  preload () {
    this.loadAssets()
    this.createView()
  }

  loadAssets () {
    this.load.atlas('boom', 'assets/plane/boom.png', 'assets/plane/boom.json')
    this.load.image('bg', 'assets/plane/bg.jpg')
    this.load.image('common', 'assets/plane/Common.png')
    this.load.image('bullet', 'assets/plane/bullet.png')
    this.load.image('hero', 'assets/plane/hero.png')
    this.load.image('enemy', 'assets/plane/enemy.png')
    this.load.audio('boom_audio', 'assets/plane/boom.mp3')
    this.load.audio('bgm_audio', 'assets/plane/bgm.mp3')
    this.load.audio('bullet_audio', 'assets/plane/bullet.mp3')
    this.load.image('btn', 'assets/start-button.png')

    this.load.onFileComplete.add((p) => {

    })
  }

  createView () {
    const preloadSprite = this.game.add.sprite(0, 0, 'loading')
    preloadSprite.top = (this.game.height - preloadSprite.height) / 2
    preloadSprite.left = (this.game.width - preloadSprite.width) / 2
    this.game.load.setPreloadSprite(preloadSprite)
  }
  create () {
    if (this.initState) {
      this.state.start(this.initState)
    } else {
      this.state.start('Play')
    }
  }
}
